import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:view_lamp/custom/custom_view_lamp10.dart';
import 'package:view_lamp/custom/custom_view_lamp11.dart';
import 'package:view_lamp/custom/custom_view_lamp6.dart';
import 'package:view_lamp/custom/custom_view_lamp7.dart';
import 'package:view_lamp/custom/view_lamp_item.dart';

import 'lamp_widget.dart';

///跳变
///黄云音
///2020年3月1日
class CustomViewLamp12 extends StatefulWidget {
  final double multiColorWidth;
  final double multiColorHeight;
  final List<Color> colorList;
  const CustomViewLamp12({
    Key key,
    this.multiColorWidth,
    this.multiColorHeight,
    this.colorList,
  }) : super(key: key);

  @override
  _CustomViewLamp12State createState() => _CustomViewLamp12State();
}

class _CustomViewLamp12State extends State<CustomViewLamp12> {
  Timer timer;

  int _currentMode = 0;

  List<Color> colorList = [
    Color(0xFFFF0000),
    Color(0xFF00FF00),
    Color(0xFF0000FF),
    Color(0xFFFFFF00),
    Color(0xFF00FFFF),
    Color(0xFFFF00FF),
  ];

  // List<Color> list =[];
  List<ViewLampItem> lampItemInfoList = [
    ViewLampItem(17, 72, Colors.transparent, 'assets/images/previewbulb1-x17y72.png'),
    ViewLampItem(82, 90, Colors.transparent, 'assets/images/previewbulb2-x82y90.png'),
    ViewLampItem(147, 104, Colors.transparent, 'assets/images/previewbulb3-x147y104.png'),
    ViewLampItem(213, 106, Colors.transparent, 'assets/images/previewbulb4-x213y106.png'),
    ViewLampItem(279, 101, Colors.transparent, 'assets/images/previewbulb5-x279y101.png'),
    ViewLampItem(344, 90, Colors.transparent, 'assets/images/previewbulb6-x344y90.png'),
    ViewLampItem(409, 73, Colors.transparent, 'assets/images/previewbulb7-x409y73.png'),
    ViewLampItem(474, 60, Colors.transparent, 'assets/images/previewbulb8-x474y60.png'),
    ViewLampItem(540, 60, Colors.transparent, 'assets/images/previewbulb9-x540y60.png'),
    ViewLampItem(606, 70, Colors.transparent, 'assets/images/previewbulb10-x606y70.png'),
    ViewLampItem(670, 87, Colors.transparent, 'assets/images/previewbulb11-x670y87.png'),
    ViewLampItem(736, 102, Colors.transparent, 'assets/images/previewbulb12-x736y102.png'),
  ];

  @override
  void initState() {
    super.initState();
    timer = Timer.periodic(Duration(seconds: 7), (Timer t) => colorValue());
  }

  void colorValue() {
    setState(() {
      if (_currentMode == 3) {
        _currentMode = 0;
      } else {
        _currentMode++;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    if (_currentMode == 0) {
      return CustomViewLamp6(multiColorWidth: widget.multiColorWidth, multiColorHeight: widget.multiColorHeight);
    } else if (_currentMode == 1) {
      return CustomViewLamp7(multiColorWidth: widget.multiColorWidth, multiColorHeight: widget.multiColorHeight);
    } else if (_currentMode == 2) {
      return CustomViewLamp10(multiColorWidth: widget.multiColorWidth, multiColorHeight: widget.multiColorHeight);
    } else if (_currentMode == 3) {
      return CustomViewLamp11(multiColorWidth: widget.multiColorWidth, multiColorHeight: widget.multiColorHeight);
    }
    throw ArgumentError('$_currentMode outsied');
  }

  @override
  void dispose() {
    timer?.cancel();
    super.dispose();
  }
}